package com.example.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.example.pojo.Customer;
import com.example.pojo.Materialzhu;
import com.example.pojo.Xs_bj;
import com.example.service.XsbjBiz;
import com.example.vo.CustVo;
import com.example.vo.LrygVo;
import com.example.vo.LsjyVo;
import com.example.vo.Matvo;
import com.example.vo.PageBean;

@RestController
@RequestMapping("/xs")
public class BjController {
	@Autowired
	private XsbjBiz biz;	
	public XsbjBiz getBiz() {
		return biz;
	}

	public void setBiz(XsbjBiz biz) {
		this.biz = biz;
	}

	/**
	 * 进入xsbj的界面
	 * @return
	 */
	@RequestMapping("/xsbj")
	public ModelAndView index(){ 
		ModelAndView view=new ModelAndView("xsbj");
		return view ;
	}
	//窗体加载时 分页查询
	@RequestMapping("/querybypage")
	@ResponseBody
	public PageBean page(Integer pagenum){
	   return biz.queryallbypage(pagenum, 1);
	}
	//点击保存时，新增或者修改主详表
    @RequestMapping(value="/addbj" ,produces = {"text/html;charset=utf-8"})
    @ResponseBody
    public String addbj(String bj){
        Xs_bj bjs=JSON.parseObject(bj,Xs_bj.class);
        String date=bjs.getBilldate().substring(0,10);
        String date2=bjs.getValiddate().substring(0,10);
        bjs.setBilldate(date);
        bjs.setValiddate(date2);
        biz.insertbj(bjs);
        return "保存成功";
    }
    //点击删除时，删除主详表
    @RequestMapping(value="/deletebj" ,produces = {"text/html;charset=utf-8"})
    @ResponseBody
    public String deletebj(String bno){
    	biz.removebj(bno);
    	return "删除成功";
    }
	//查询并且产生单号的方法
    @RequestMapping("/querymax")
	@ResponseBody
	public String querymax(String dd){
    	String dates=dd.substring(0,10);
    	String ss=biz.querymax(dates);
        return ss;   
	}
    //查询所有的客户信息
    @RequestMapping("/querycust")
	@ResponseBody
	public List<Customer> quetycust(){
	   return biz.findcust();
	}
   
    //点击取回时，加载的信息
    @RequestMapping("/querycustbyid")
   	@ResponseBody
    public CustVo querybycid(String cid){
    	return biz.querybycid(cid);
    }
    //datagrid按下时查找所有的物料
    @RequestMapping("/querymater")
   	@ResponseBody
   	public List<Materialzhu> quetymat(){
   	   return biz.querymat();
   	}
    
    @RequestMapping("/querymatbyidss")
   	@ResponseBody
    public Matvo querymtbycid(String mid){
    	return biz.querybymatid(mid);
    }
    
    
    
  //点击删除时，删除主详表
    @RequestMapping(value="/bjsh" ,produces = {"text/html;charset=utf-8"})
    @ResponseBody
    public String shenhe(String bno){
    	try {
    		biz.updatebjstatus(bno);
    		return "审核成功";
		} catch (Exception e) {
			return "该单已审核,不能进行重复审核";
		}   	
    }
    
    @RequestMapping(value="/bjfsh" ,produces = {"text/html;charset=utf-8"})
    @ResponseBody
    public String fshenhe(String bno){
    	try {
    		biz.updatebjstatus2(bno);
        	return "反审核成功";
		} catch (Exception e) {
			return "该单还未审核，不能进行反审核";
		}
    	
    }
    
    //datagrid按下时查找所有的物料
    @RequestMapping("/querybycust")
   	@ResponseBody
   	public List<LsjyVo> quebycust(String cust){
   	   return biz.querybycust(cust);
   	}
    
    @RequestMapping("/querybycust2")
   	@ResponseBody
   	public List<LsjyVo> quebycust2(String cust){
   	   return biz.querybycust2(cust);
   	}
    
    @RequestMapping("/querybycust3")
   	@ResponseBody
   	public List<LsjyVo> quebycust3(String cust){
   	   return biz.querybycust3(cust);
   	}
    
    @RequestMapping("/querybybills")
   	@ResponseBody
   	public List<LrygVo> querybybills(String bill){
   	   return biz.querybybill(bill);
   	}
}
